package com.spt.core;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

public class CustomExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
            Exception ex) {
        if(ex instanceof UnauthenticatedException){
            ex.printStackTrace();
            SecurityUtils.getSubject().logout();  
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.setViewName("redirect:/");
            return new ModelAndView("redirect:/");
        }else {
            ex.printStackTrace();
        }
        return null;
    }

}
